//
//  BaseTableViewController.swift
//  Sina
//
//  Created by 管观荣 on 15/9/21.
//  Copyright © 2015年 CHer. All rights reserved.
//

import UIKit


//用来处理访客没有登录的控制器基类
class BaseTableViewController: UITableViewController {

    //记录用户是否登录
   
    var userLogon = UserAccountViewModel.sharedAccountViewModel.userLogon

    //访客视图视图，不能用懒加载
    var visitView: VisitView?
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        
    }
    override func loadView() {
        //如果登录，使用系统默认的视图 － UITableView，否则显示访客视图
        userLogon ? super.loadView() : setupVisitView()
    }
    private func setupVisitView(){
        
        visitView = VisitView()
        view = visitView
        
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", style: .Plain, target: self, action:"registBtnClick")
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登录", style: .Plain, target: self, action: "loginBtnClick")
        
        visitView?.registBtn.addTarget(self, action: "registBtnClick", forControlEvents: UIControlEvents.TouchUpInside)
        visitView?.loginBtn.addTarget(self, action: "loginBtnClick", forControlEvents: UIControlEvents.TouchUpInside)
        
    }
   @objc private func registBtnClick(){
        print("注册")
    }
   @objc private func loginBtnClick(){
        let oauth = OAuth()
        let nav = UINavigationController(rootViewController: oauth)
        presentViewController(nav, animated:true, completion: nil)
    }

}
